﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace SmartMathLibrary.Management.Performance
{
    /// <summary>
    /// This class provides a special thread, which allows the developer to suspend and resume the 
    /// thread sessions. Overwrite the Work() method to realize the thread action method.
    /// </summary>
    [Serializable]
    public abstract class AbstractSuspendableThread : AbstractThread
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AbstractSuspendableThread"/> class.
        /// </summary>
        protected AbstractSuspendableThread()
            : base()
        {
            this.thread = new Thread(new ThreadStart(this.Worker));
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="AbstractSuspendableThread"/> class.
        /// </summary>
        /// <param name="refreshRate">The refresh rate for checking if the thread was set to resume state.</param>
        protected AbstractSuspendableThread(TimeSpan refreshRate)
            : base(refreshRate)
        {
            this.thread = new Thread(new ThreadStart(this.Worker));
        }

        /// <summary>
        /// This method provides the thread start. Overwrite this method to use it.
        /// </summary>
        public abstract void Worker();
    }
}